************************************************************************************************ EXPTREATTEST
**** This program compares means and equality of means at different quantiles********************************************************************************************

	capt prog drop exptreattest

	program exptreattest, eclass

	syntax varlist [if] [in], [ * ]
	marksample touse
	markout `touse'
	tempname c_1 se_1 t_1 c_2 se_2 t_2 c_3 se_3 t_3 cf_1 sef_1 tf_1 cf_2 sef_2 tf_2 cf_3 sef_3 tf_3 obs
                           
	foreach var of local varlist {
	
	* BASELINE
			
		qui reg `var' mother if `touse' & round == 2010 & group == 1, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `c_1' = nullmat(`c_1'), b[1,1]
			mat `se_1' = nullmat(`se_1'), sqrt(v[1,1])
			mat `t_1' = nullmat(`t_1'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
			
		qui reg `var' mother if `touse' & round == 2010 & group == 2, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `c_2' = nullmat(`c_2'), b[1,1]
			mat `se_2' = nullmat(`se_2'), sqrt(v[1,1])
			mat `t_2' = nullmat(`t_2'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
			
		qui reg `var' mother if `touse' & round == 2010 & group == 3, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `c_3' = nullmat(`c_3'), b[1,1]
			mat `se_3' = nullmat(`se_3'), sqrt(v[1,1])
			mat `t_3' = nullmat(`t_3'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
			

	* FOLLOW-UP
		
		qui reg `var' mother if `touse' & round == 2012 & group == 1, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `cf_1' = nullmat(`cf_1'), b[1,1]
			mat `sef_1' = nullmat(`sef_1'), sqrt(v[1,1])
			mat `tf_1' = nullmat(`tf_1'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
			
		qui reg `var' mother if `touse' & round == 2012 & group == 2, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `cf_2' = nullmat(`cf_2'), b[1,1]
			mat `sef_2' = nullmat(`sef_2'), sqrt(v[1,1])
			mat `tf_2' = nullmat(`tf_2'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
			
		qui reg `var' mother if `touse' & round == 2012 & group == 3, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `cf_3' = nullmat(`cf_3'), b[1,1]
			mat `sef_3' = nullmat(`sef_3'), sqrt(v[1,1])
			mat `tf_3' = nullmat(`tf_3'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
					
													
	}
		
	foreach mat in c_1 se_1 t_1 c_2 se_2 t_2 c_3 se_3 t_3 cf_1 sef_1 tf_1 cf_2 sef_2 tf_2 cf_3 sef_3 tf_3 {
		mat coln ``mat'' = `varlist'
	}

	tempname b V
	mat `b' = `c_1'*0
	mat `V' = `b''*`b'
	eret post `b' `V'
	eret local cmd "exptreattest"
	
	mat temp = `obs'
	eret scalar N1 = temp[1,1] 
	eret scalar N2 = temp[1,2] 
	eret scalar N3 = temp[1,3] 
	eret scalar N4 = temp[1,4] 
	eret scalar N5 = temp[1,5] 
	eret scalar N6 = temp[1,6] 
	
	
	foreach mat in c_1 se_1 t_1 c_2 se_2 t_2 c_3 se_3 t_3 cf_1 sef_1 tf_1 cf_2 sef_2 tf_2 cf_3 sef_3 tf_3 obs {
		eret mat `mat' = ``mat''
	}
	
	end
